﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;
using System.Data;

namespace BUS
{
    public class HoaDonBUS
    {
        public static int ThemHoaDon(HoaDonDTO hd)
        {
            DataTable dt = HoaDonDAO.Themhoadon(hd);
            return int.Parse(dt.Rows[0]["ID"].ToString());
        }
        public static List<HoaDonDTO> ListHD()
        {
            DataTable dt = HoaDonDAO.ListHoaDon();
            List<HoaDonDTO> lstHoadon = null;
            if (dt != null)
            {
                lstHoadon = new List<HoaDonDTO>();
                foreach (DataRow dr in dt.Rows)
                {
                    HoaDonDTO kv = new HoaDonDTO();
                    kv.Mahd = int.Parse(dr["MAHD"].ToString());
                    kv.Ngaylap = DateTime.Parse(dr["NGAYLAP"].ToString());
                    kv.Madatmon = int.Parse(dr["MADM"].ToString());
                    kv.Nguoilap = int.Parse(dr["NVLAP"].ToString());
                    kv.Tongtien = float.Parse(dr["TONGTIEN"].ToString());

                    lstHoadon.Add(kv);
                }
            }
            return lstHoadon;
        }
    }
}
